package com.sx.gongzhong.pest;

import com.sx.gongzhong.model.HeadParamBean;
import com.sx.gongzhong.model.ReplyUserBean;
import com.sx.gongzhong.net.ApiManager;
import com.sx.gongzhong.net.BaseCallBack;
import com.sx.gongzhong.view.VerifyCodeView;

import java.util.HashMap;
import java.util.Map;

/**获取注册验证码
 * Created by admin on 2018/1/8.
 */

public class VerifyCodePest {
    private VerifyCodeView verifyCodeView;

    public VerifyCodePest(VerifyCodeView verifyCodeView) {
        this.verifyCodeView = verifyCodeView;
    }
    //获取验证码
    public void getVerifyCode(String phone,int type) {
        Map<String,Object> map = HeadParamBean.getHead();
        map.put("phone",phone);
        new ApiManager().getVerifyCode(map,type, new BaseCallBack<ReplyUserBean.BaseResult<Boolean>>() {
            @Override
            public void onSuccess(ReplyUserBean.BaseResult<Boolean> response) {
                verifyCodeView.getVerifyCodeSuccess(response.data);
            }
            @Override
            public void onFailures(String message) {
                verifyCodeView.showError(message);
            }
        });
    }
    //校验验证码
    public void checkVerifyCode(String phone,String verifyCode,int type) {
        Map<String,Object> map = new HashMap<>();
        map.put("phone",phone);
        map.put("verifyCode",verifyCode);
        new ApiManager().checkVerifyCode(map,type, new BaseCallBack<ReplyUserBean.BaseResult<String>>() {
            @Override
            public void onSuccess(ReplyUserBean.BaseResult<String> response) {
                verifyCodeView.checkVerifyCodeSuccess(response.data);
            }
            @Override
            public void onFailures(String message) {
                verifyCodeView.showError(message);
            }
        });
    }

    //修改手机号
    public void updatePhone(String phone,String verifyCode) {
        Map<String,Object> map = HeadParamBean.getHead();
        map.put("phone",phone);
        map.put("verifyCode",verifyCode);
        new ApiManager().updatePhone(map,new BaseCallBack<ReplyUserBean.BaseResult<Void>>() {
            @Override
            public void onSuccess(ReplyUserBean.BaseResult<Void> response) {
                if(response.success) {
                    verifyCodeView.checkVerifyCodeSuccess("修改成功");
                }
            }
            @Override
            public void onFailures(String message) {
                verifyCodeView.showError(message);
            }
        });
    }
}
